<template>
  <!-- 添加或修改项目基础信息管理对话框 -->
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body v-dialogDrag width="90%">

    <el-form :inline="true" :model="queryParams" label-width="98px" ref="queryForm" size="small">
      <el-form-item label="产品名称" prop="goodsName">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入产品名称" v-model="queryParams.goodsName"/>
      </el-form-item>
      <el-form-item label="产品型号" prop="code">
        <el-input @keyup.enter.native="handleQuery" clearable
                  placeholder="请输入产品型号" v-model="queryParams.goodModel"/>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery" icon="el-icon-search" size="mini" type="primary">搜索</el-button>
        <el-button @click="resetQuery" icon="el-icon-refresh" size="mini">重置</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini"
                   @click="handleExport" >导出
        </el-button>
      </el-form-item>
    </el-form>

    <el-form ref="form" :model="form" :rules="rules">
      <el-table :data="columns" ref="dragTable" row-key="id" v-loading="loading" @sort-change="handleSortChange" :max-height="maxHeight">
        <el-table-column align="center" label="序号" type="index" width="50">
          <template slot-scope="scope">
            <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable label="产品编码" align="center" prop="goodsCode"/>
        <el-table-column sortable align="center" label="产品名称" prop="goodsName" show-overflow-tooltip/>
        <el-table-column sortable align="center" label="产品型号" prop="goodModel"/>
         <el-table-column sortable label="产品状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.goods_status" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column sortable align="center" label="产品类型" prop="type"/>
        <el-table-column align="center" label="产品单位" prop="unit"/>
        <!-- <el-table-column align="center" label="订单单价" prop="goodsUnitPrice"/> -->
        <el-table-column align="center" label="订单数量" prop="orderCount"/>
        <el-table-column align="center" label="需求日期" prop="deliveryTime"/>
        <el-table-column align="center" label="锁定数量" prop="lockCount"/>
        <el-table-column label="是否自制" align="center" prop="isdo">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.isdo" :value="scope.row.isdo"/>
          </template>
        </el-table-column>
        <el-table-column align="center" label="(请购/自制)数量" prop="pleaseBuyCount"/>
        <el-table-column align="center" label="备注" prop="remark" show-overflow-tooltip/>
      </el-table>
    </el-form>
    <div class="dialog-footer" slot="footer">
     <!-- <el-button type="primary" @click="submitBuyForm">发起请购</el-button>-->
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>


<script>

import {addAction, deleteAction, downloadFile, getAction, getById} from '@/api/manage'

export default {
  name: "PleaseBuyGoodsList",
  dicts: ['isdo','goods_status'],
  components: {
    /* GoodsOrderinChose,
     GoodSaleForm*/
  },
  data() {
    return {
      maxHeight: (window.innerHeight * 0.9 - 260) ,
      // 遮罩层
      loading: true,
      activeName: "first",
      // 弹出层标题
      title: "产品请购",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      proId: "",
      status: "",
      columns: [],
      total: 0,
      // 表单校验
      rules: {},
      queryParams: {
        pageNum: 1,
        pageSize: 1000,
        id: null,
        name: null,
        taxNo: null,
        addr: null,
        tel: null,
        bankName: null,
        bankNo: null,
        info: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        type: null,
        lvdoId: null,
        lvdoNo: null,
        mainId: null,
      },
      url: {
        list: '/goodsSaledo/goodsSaledo/listQinggouAll',
        pleaseBuyForPrj: '/goodsSaledo/goodsSaledo/pleaseBuyForPrj',
        export: '/goodsSaledo/goodsSaledo/exportByPleaseBuy',
      },
    };
  },
  created() {

  },
  methods: {
      /** 排序触发事件 */
		handleSortChange(column, prop, order) {
		  this.queryParams.orderByColumn = column.prop;
		  this.queryParams.isAsc = column.order;
		  this.handleQuery();
		},    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.goodModel = ''
      this.resetForm("queryForm");
      this.handleQuery();
    },
    refreshPageData() {
      let that = this;
      let param = {
        id: that.proId
      }
      that.handleUpdate(param);
    },
    handleChose() {
      this.$refs.formChose.chose(this.proId, "2");
    },
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.columns = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        name: null,
        master: null,
        customId: null,
        customName: null,
        companyName: null,
        contractDate: null,
        contractMoney: null,
        auditMoney: null,
        checkDate: null,
        checkState: null,
        fundCallback: null,
        infomation: null,
      };
      this.resetForm("form");
    },
    /** 修改按钮操作 */
    handleShow(row) {
      this.reset();
      this.queryParams.mainId = row.id;
      // this.queryParams.status=row.status;
      // this.queryParams.projectId = row.mainId;
      this.open = true;
      this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      downloadFile(this.url.export, this.queryParams);
    },

  }
};
</script>
